package com.oauth.application.client.ui;

import java.util.List;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratedStackPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.application.client.beans.ApplicationClientBean;
import com.oauth.application.client.rpc.ApplicationRemoteServiceAsync;

public class MyApplications extends Composite {

	private static MyApplicationUiBinder uiBinder = GWT.create(MyApplicationUiBinder.class);

	interface MyApplicationUiBinder extends UiBinder<Widget, MyApplications> {
	}

	@UiField
	DecoratedStackPanel stackPanel;

	@UiField
	VerticalPanel vPanel;

	public MyApplications() {
		initWidget(uiBinder.createAndBindUi(this));
		stackPanel.setStackText(0, "<div class=\"stackText\">My Applications</div>", true);

	}

	public void addApplications(List<ApplicationClientBean> pResult,
			ApplicationRemoteServiceAsync applicationUnSubscribeRemoteServiceAsync) {

		vPanel.clear();
		for (ApplicationClientBean application : pResult) {
			vPanel.add(new ApplicationItem(application));
		}
		if (pResult.size() < 3) {
			vPanel.add(new HTML("<a align=\"right\" href=\"/browse.html\">Add &raquo;</a>"));
		}
	}

}
